import { getStorage } from "@/utils/localstoreage";
import { uSelectUserInfo } from "./../../api/user";
import { observable, action, computed } from 'mobx'
import { createContext } from 'react';
import Taro from "@tarojs/taro";
import ChildrenPageUtils from "@/store/extends";


class User extends ChildrenPageUtils {
  @observable visible: boolean = false
  @action.bound
  changeVisible(bol: boolean) {
    this.visible = bol
  }

  @observable pageData: {
    devCount: number
    user: UserSetting.UserInfo | null
  } = {
    devCount: 0,
    user: null
  }
  @action.bound
  async updatePageDataSource() {
    let userId = getStorage('userId')
    if (!userId) return
    let res = await uSelectUserInfo({userId})
    if (res && res.result === 'success') {
      this.pageData = res.data
    } else {
      this.pageData = {
        devCount: 0,
        user: null
      }
    }
  }
}

export const userStore = createContext(new User())

Object.prototype